﻿using System;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using HalconDotNet;
using System.Windows.Data;
using System.Collections.ObjectModel;

namespace BindingWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }
    }

    // Converter to reduce the decimal places provided by image part
    public class ImagePartDecimalPlaceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                string[] ImagePartArg = value.ToString().Split(';');

                string shortForm = ImagePartArg[0].Split(',').First() + ','
                                   + ImagePartArg[1].Split(',').First() + ','
                                   + ImagePartArg[2].Split(',').First() + ','
                                   + ImagePartArg[3].Split(',').First();
                return shortForm;
            }
            catch(Exception)
            {
                // In error case, just return the input value, do nothing
                return value.ToString();
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Nothing to do in set mode
            return value.ToString();
        }
    }
}

